import 'dart:collection';

import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:tender_flutter/constant/api_path.dart';
import 'package:tender_flutter/http/api_response.dart';
import 'package:tender_flutter/http/http_utils.dart';

class ApiCollection {
  /// 招投标信息收藏/取消
  static Future tenderCollection<T>({@required int tenderId}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["id"] = tenderId;
      final response =
          await HttpUtils.post(ApiPath.tenderCollection, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 资质信息收藏/取消
  static Future certificationCollection<T>({@required String cerId}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["id"] = cerId;
      final response =
          await HttpUtils.post(ApiPath.certificationCollection, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 企业信息收藏/取消
  static Future businessCollection<T>(
      {@required String companyName, @required String companyKey}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["companyName"] = companyName;
      params["companyKey"] = companyKey;
      final response =
          await HttpUtils.post(ApiPath.businessCollection, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 供需信息收藏/取消
  static Future marketCollection<T>({@required int marketId}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["market"] = marketId;
      final response =
          await HttpUtils.get(ApiPath.marketCollection, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }
}
